/*
 * Copyright (c) 2024. hallele, Inc All rights reserved.
 */

package cn.hallele.ms.starter.web.framework.publisher;

import cn.hallele.ms.starter.web.framework.context.ActionContext;
import cn.hallele.ms.starter.web.framework.event.ActionBusinessFinishedEvent;
import cn.hallele.ms.starter.web.framework.event.ActionContextInitializedEvent;
import cn.hallele.ms.starter.web.framework.event.ActionFinishedEvent;
import cn.hallele.ms.starter.web.framework.event.ActionRequestFilledEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;

/**
 * action基础流程事件发布者
 *
 * @author anle5
 * @since 2024/12/23 22:35
 */
@Slf4j
@Component
public class ActionEventPublisher {
    @Autowired
    private ApplicationEventPublisher publisher;

    /**
     * 发布上下文初始化完成事件
     *
     * @param context 上下文
     */
    public void publishContextInitializedEvent(ActionContext context) {
        log.info("Publish framework action context initialized event.");
        publisher.publishEvent(new ActionContextInitializedEvent(context));
    }

    /**
     * 发布补全请求事件
     *
     * @param context 上下文
     */
    public void publishRequestFilledEvent(ActionContext context) {
        log.info("Publish framework action request filled event.");
        publisher.publishEvent(new ActionRequestFilledEvent(context));
    }

    /**
     * 发布具体action业务逻辑执行完成事件
     *
     * @param context 上下文
     */
    public void publishChainFinishedEvent(ActionContext context) {
        log.info("Publish framework action chain finished event.");
        publisher.publishEvent(new ActionBusinessFinishedEvent(context));
    }

    /**
     * 发布action完成事件
     *
     * @param context 上下文
     */
    public void publishFinishedEvent(ActionContext context) {
        log.info("Publish framework action finished event.");
        publisher.publishEvent(new ActionFinishedEvent(context));
    }
}
